# StartTCL: n
#
# Threat System
#
# This program is (c) 2006 by Spirit <thehiddenspirit@hotmail.com>
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. You can also consult
# the terms of the license at:
#
#		<http://www.gnu.org/copyleft/lesser.html>
#
# Description: make mobs change target according to threat level
#
# Setup: Apply spell patches (spell-patch.txt and autoban_patch.txt)
#

namespace eval ::Threat {

	variable NAME "Threat"
	variable AUTHOR "Spirit"
	variable VERSION 0.32

	variable ENABLED 1
	variable WEAPON_RATE 1.0
	variable SPELL_RATE 1.0
	variable RESTORE_RATE 0.5
	variable THRESHOLD 110

	variable USE_CONF 1
	variable DEBUG 0

	if {$USE_CONF} {
		::Custom::LoadConf
	}

	if {!$ENABLED} {
		namespace delete [namespace current]
		return
	}

	::StartTCL::Require "StartTCL" 0.9.5

	# spell effect 63 (change threat level towards the target)
	# spellid -> threat
	array set SpellThreat {
		781 -140
		1515 10
		1742 -30
		1753 -55
		1754 -85
		1755 -125
		1756 -175
		1966 -150
		2649 50
		3716 45
		4045 50
		4049 100
		5729 15
		6360 -45
		6393 25
		6394 40
		6395 55
		6664 -1000
		6768 -240
		6994 -50
		7390 375
		7391 600
		7809 75
		7810 125
		7811 215
		7813 -75
		8223 600
		8347 5000
		8351 5
		8353 -500
		8354 500
		8506 10
		8507 15
		8637 -390
		8913 0
		8974 110
		8975 170
		8976 240
		8998 -240
		9000 -390
		9870 320
		9871 415
		9892 -600
		10423 75
		10424 100
		11303 -600
		11308 25
		11309 30
		11588 850
		11589 1125
		11590 1450
		11774 300
		11775 395
		11784 -130
		11785 -165
		14272 -280
		14273 -405
		14274 160
		14916 65
		14917 110
		14918 170
		14919 240
		14920 320
		14921 415
		15629 250
		15630 350
		15631 465
		15632 600
		16193 110
		16697 -225
		17357 155
		17358 200
		17735 150
		17750 300
		17751 450
		17752 600
		17967 400
		19548 10
		19674 10
		19687 10
		19688 10
		19689 10
		19692 10
		19693 10
		19694 10
		19696 10
		19697 10
		19699 10
		19700 10
		19808 350
		20232 0
		20544 4000
		20736 110
		20859 0
		21794 10
		21866 10
		22765 0
		22786 500
		23015 50000
		23311 0
		23604 -540
		24211 5000
		24394 580
		24700 500

		25302 -800
	}

	# increase threat level towards all attackers
	variable SpellThreatAttackers
	array set SpellThreatAttackers {
	}

	# spell effect 91 (change all threat levels towards the target)
	# spellid -> threat
	variable SpellThreatAll
	array set SpellThreatAll {
		8127 -300
		8194 -600
	}

	# spell effect 6 (temporary), spell aura 10 (mod generated threat)
	# spellid -> threat %
	variable SpellModThreat
	array set SpellModThreat {
		77 0
		1036 50
		1038 -30
		4101 20
		4525 15
		12303 0
		12788 5
		12789 10
		12791 10
		12792 15
		17179 10000
		21156 -20
		21178 30
		21184 -20
		23545 -15
		24701 -75
	}

	# spell effect 6 (temporary), spell aura 103 (mod threat level)
	# added Demoralizing Roar, Faerie Fire, Faerie Fire (Feral), Demoralizing Shout
	# added Battle Shout, Sunder Armor
	# todo: maybe seperate array/proc for those spells (mod threat level towards one target)
	# spellid -> threat
	variable SpellModTotalThreat
	array set SpellModTotalThreat {
		586 -55
		9578 -155
		9579 -285
		9592 -440
		10941 -620
		10942 -820
		12685 -55
		15432 -335
		15433 -400
		21976 -800


		99 10
		1735 16
		9490 21
		9747 32
		9898 42

		770 37
		778 61
		9749 84
		9907 108

		16857 37
		17390 61
		17391 84
		17392 108

		1160 11
		6190 17
		11554 22
		11555 32
		11556 43


		6673 5
		5242 11
		6192 17
		11549 26
		11550 40
		11551 57
		25289 71

		7386 52
		7405 104
		8380 157
		11596 209
		11597 261
	}

	# mod total threat on target (immunity, confuse (5), stun (12), root (26))
	# spellid -> threat
	variable SpellModTotalThreatTarget
	array set SpellModTotalThreatTarget {
		498 -100000000
		642 -100000000
		1020 -100000000
		1022 -100000000
		3122 -100000000
		3169 -100000000
		5573 -100000000
		5599 -100000000
		6724 -100000000
		7144 -100000000
		9438 -100000000
		10278 -100000000
		11089 -100000000
		11958 -100000000
		12890 -100000000
		13007 -100000000
		13235 -100000000
		13835 -100000000
		13874 -100000000
		16451 -100000000
		17177 -100000000
		17674 -100000000
		21892 -100000000
		23415 -100000000
		27619 -100000000

		113 -100000000
		118 -100000000
		122 -100000000
		339 -100000000
		512 -100000000
		700 -100000000
		710 -100000000
		865 -100000000
		1062 -100000000
		1090 -100000000
		1968 -100000000
		1969 -100000000
		1970 -100000000
		2128 -100000000
		2129 -100000000
		2637 -100000000
		2937 -100000000
		3260 -100000000
		3263 -100000000
		3635 -100000000
		3636 -100000000
		3651 -100000000
		5195 -100000000
		5196 -100000000
		5219 -100000000
		5276 -100000000
		5567 -100000000
		6131 -100000000
		6728 -100000000
		6894 -100000000
		7144 -100000000
		7295 -100000000
		7761 -100000000
		7967 -100000000
		8040 -100000000
		8399 -100000000
		8994 -100000000
		9159 -100000000
		9256 -100000000
		9484 -100000000
		9485 -100000000
		9852 -100000000
		9853 -100000000
		9915 -100000000
		10017 -100000000
		10230 -100000000
		10234 -100000000
		10955 -100000000
		11444 -100000000
		11641 -100000000
		11831 -100000000
		11836 -100000000
		12098 -100000000
		12674 -100000000
		12748 -100000000
		12824 -100000000
		12825 -100000000
		12826 -100000000
		12890 -100000000
		13323 -100000000
		14621 -100000000
		14907 -100000000
		15063 -100000000
		15283 -100000000
		15531 -100000000
		15532 -100000000
		15534 -100000000
		15535 -100000000
		15970 -100000000
		16097 -100000000
		16798 -100000000
		16869 -100000000
		17276 -100000000
		17293 -100000000
		17492 -100000000
		17738 -100000000
		18503 -100000000
		18647 -100000000
		18657 -100000000
		18658 -100000000
		18763 -100000000
		19501 -100000000
		19970 -100000000
		19971 -100000000
		19972 -100000000
		19973 -100000000
		19974 -100000000
		19975 -100000000
		20066 -100000000
		20478 -100000000
		20669 -100000000
		22274 -100000000
		22566 -100000000
		22645 -100000000
		22651 -100000000
		23103 -100000000
	}

	# weapon damage (spell effect 17, 58, 78)
	# spellid -> added threat
	variable SpellWeapon
	array set SpellWeapon {
		53 15
		78 11
		284 21
		285 32
		845 5
		1082 27
		1464 32
		1608 44
		1752 3
		1757 6
		1758 10
		1759 15
		1760 22
		2589 30
		2590 48
		2591 69
		3029 39
		3231 50
		5019 0
		5201 57
		6564 32
		6566 50
		7369 10
		7384 5
		7812 305
		7887 15
		8621 33
		8676 70
		8721 90
		8724 100
		8725 125
		8820 43
		9080 1
		9633 5
		9737 50
		9849 88
		9850 115
		11267 185
		11268 230
		11269 290
		11279 135
		11280 165
		11281 210
		11293 52
		11294 68
		11564 58
		11565 80
		11566 111
		11567 138
		11584 25
		11585 35
		11604 68
		11605 87
		11608 18
		11609 32
		11998 35
		13586 0
		14099 25
		14102 5
		14873 1
		14895 15
		15576 50
		15577 200
		15578 100
		15581 3
		15589 300
		15652 10
		15667 2
		15793 5
		16511 0
		17156 10
		17198 30
		17347 0
		17348 0
		19132 25
		19434 70
		19438 510
		19440 770
		19441 1095
		19442 1470
		19443 1905
		19472 1
		19644 30
		19730 25
		19881 0
		20240 0
		20243 0
		20569 50
		20900 125
		20901 200
		20902 330
		20903 460
		20904 600
		21790 50
		22427 0
		22572 5
		22858 0
		23848 682
		23850 1130
		23959 445
		23960 374
		24407 750

		75 0
		76 24
		87 12
		278 25
		279 35
		678 22
		679 11
		680 62
		1516 5
		1628 44
		1698 46
		1834 80
		1866 39
		1960 25
		2110 0
		2480 0
		2495 101
		2643 0
		2677 3
		2679 5
		2680 8
		2681 10
		2682 12
		2697 3
		2699 5
		2700 8
		2701 10
		2702 12
		2707 5
		2709 10
		2710 13
		2711 16
		2717 3
		2719 5
		2720 8
		2721 9
		2727 5
		2728 9
		2729 12
		2730 15
		2763 0
		2764 0
		2765 0
		2973 5
		3011 20
		3035 10
		3036 20
		3037 30
		3038 40
		3130 4
		3242 3
		3446 0
		3551 1
		3597 17
		3668 50
		3743 17
		4159 19
		4160 0
		4240 20
		4281 43
		4282 45
		4520 150
		4938 100
		5208 30
		5221 54
		5422 3
		5532 10
		5568 8
		5569 129
		5708 18
		5918 30
		6174 100
		6175 150
		6186 36
		6266 10
		6409 48
		6466 70
		6568 66
		6595 20
		6685 0
		6748 0
		6785 42
		6787 62
		6800 72
		6927 58
		6975 10
		6976 15
		6977 25
		6979 30
		6980 40
		6984 15
		6985 25
		6996 50
		6998 100
		7027 50
		7028 75
		7029 100
		7092 20
		7139 20
		7145 30
		7159 10
		7160 50
		7342 5
		7394 5
		7891 40
		7896 25
		7918 0
		7919 0
		8151 30
		8255 55
		8259 50
		8275 30
		8281 3
		8285 7
		8355 30
		8363 30
		8374 0
		8391 4
		8627 10
		8682 25
		8716 15
		8806 1
		8858 0
		8992 99
		9143 1
		9829 144
		9830 180
		9866 78
		9867 98
		10101 30
		10332 167
		10333 213
		10833 10
		10887 10
		10966 50
		11130 30
		11397 1
		11410 50
		11427 10
		11837 3
		11876 23
		11902 50
		12161 5
		12166 6
		12294 85
		12461 60
		12551 0
		12612 0
		12887 50
		13953 1
		14112 10
		14260 11
		14261 21
		14262 34
		14263 50
		14264 80
		14265 110
		14266 140
		14288 40
		14289 80
		14290 120
		14443 50
		15248 10
		15284 10
		15495 100
		15496 10
		15550 0
		15579 40
		15582 30
		15584 30
		15593 50
		15613 20
		15617 30
		15621 3
		15622 30
		15623 15
		15657 20
		15663 15
		15749 150
		15754 30
		16044 50
		16169 5
		16497 1
		16636 300
		16727 50
		17143 2
		17284 3
		17307 300
		17685 15
		18072 50
		18144 54
		18375 7
		18651 75
		18670 30
		18802 0
		18813 30
		18819 30
		18945 30
		19131 75
		19319 0
		19434 0
		19471 150
		19632 50
		19633 30
		19642 40
		19777 600
		19983 50
		20605 30
		20666 30
		20677 0
		20684 30
		20686 30
		20688 600
		20691 0
		20735 225
		20751 10
		20900 0
		20901 0
		20902 0
		20903 0
		20904 0
		21188 1
		21390 100
		21551 110
		21552 135
		21553 160
		21987 2
		22120 75
		22311 350
		22334 300
		22416 40
		22540 20
		22574 100
		22886 300
		22911 75
		22916 50
		23919 500
		24016 750
		24023 75
		24042 210
		24048 50
		24071 0
		24187 100
		24193 75
		24213 500
		24316 10000
		24326 250
		24333 3
		24337 160
		24375 500
		24408 75
		25056 250

		6603 0
	}

	# spells that cause damage ([lsearch "2 9" $se] >= 0 || [lsearch "6 27 35" $se] >= 0 && [lsearch "3 53" $sa] >= 0)
	# todo: adjust Shield Bash, Revenge, Shield Slam
	# spellid -> threat
	variable SpellDamage
	array set SpellDamage {
		10 25
		12 40
		15 4
		58 5
		59 6
		60 11
		61 16
		68 11
		72 6
		101 10
		116 19
		120 103
		122 20
		133 20
		142 5
		143 41
		145 69
		172 40
		205 33
		269 5
		271 8
		315 22
		339 20
		348 28
		403 14
		421 204
		424 50
		500 20
		529 28
		545 38
		548 49
		585 15
		589 30
		591 28
		594 66
		598 58
		603 3200
		686 14
		689 10
		690 23
		694 22
		695 26
		699 17
		701 12
		703 108
		705 52
		707 59
		709 29
		711 66
		744 120
		748 8
		749 8
		751 4
		752 15
		753 17
		761 16
		762 32
		769 36
		772 15
		779 18
		780 25
		801 320
		804 77
		806 300
		837 54
		865 35
		879 90
		899 68
		911 40
		915 89
		923 118
		930 294
		937 48
		943 134
		951 168
		957 60
		963 59
		965 24
		970 132
		984 98
		992 234
		1004 160
		1050 3500
		1062 50
		1079 18
		1084 33
		1088 92
		1092 160
		1094 135
		1096 41
		1106 152
		1110 208
		1112 81
		1120 55
		1124 78
		1449 34
		1457 36
		1495 25
		1504 12
		1505 28
		1506 36
		1507 44
		1508 56
		1510 50
		1536 27
		1540 26
		1629 90
		1671 18
		1672 45
		1708 122
		1709 159
		1715 5
		1766 15
		1767 30
		1768 45
		1769 80
		1770 59
		1776 10
		1777 20
		1794 18
		1795 43
		1796 70
		1797 82
		1798 89
		1822 58
		1823 85
		1824 118
		1918 11
		1920 24
		1921 28
		1922 35
		1933 39
		1940 30
		1943 15
		1947 190
		1949 1245
		1955 4
		1956 7
		1957 11
		1958 13
		1959 17
		1963 19
		1964 44
		1965 57
		1967 87
		1971 13
		1972 18
		1973 24
		1975 80
		1976 120
		1977 131
		1978 20
		1980 26
		2098 3
		2111 23
		2112 30
		2113 37
		2120 72
		2121 131
		2128 235
		2129 365
		2130 415
		2131 529
		2136 28
		2137 64
		2138 115
		2431 26
		2537 12
		2606 58
		2607 24
		2608 113
		2609 190
		2610 269
		2616 62
		2617 108
		2626 131
		2627 4
		2628 7
		2629 9
		2630 10
		2653 100
		2676 75
		2712 33
		2722 20
		2731 33
		2767 366
		2797 200
		2812 395
		2816 100
		2818 36
		2819 52
		2860 401
		2912 99
		2922 52
		2941 255
		2943 8
		2944 19
		2948 59
		2951 95
		2969 5
		2974 5
		3005 170
		3007 35
		3009 51
		3010 42
		3013 33
		3015 33
		3018 2
		3044 13
		3052 5
		3053 15
		3054 30
		3055 50
		3106 38
		3108 70
		3110 7
		3121 12
		3129 25
		3131 10
		3132 24
		3140 112
		3143 35
		3147 4
		3204 150
		3205 1
		3206 1
		3207 1
		3234 13
		3243 15
		3261 167
		3322 15
		3339 30
		3356 30
		3358 15
		3361 45
		3387 360
		3388 30
		3393 30
		3396 60
		3466 87
		3477 1000
		3479 10
		3481 15
		3485 75
		3583 24
		3585 45
		3587 90
		3602 50
		3606 10
		3607 1
		3674 150
		3712 307
		3717 30
		3718 100
		3815 450
		3822 100
		4043 450
		4050 150
		4054 30
		4061 60
		4062 150
		4064 25
		4065 50
		4066 85
		4067 100
		4068 175
		4069 175
		4102 15
		4164 26
		4165 43
		4244 28
		4280 50
		4285 60
		4286 155
		4320 120
		4504 6
		4505 6
		4514 210
		4538 50
		4629 75
		4940 100
		5010 45
		5024 1500
		5100 50
		5105 150
		5113 25
		5137 10
		5154 3
		5156 10
		5158 25
		5159 140
		5176 13
		5177 27
		5178 48
		5179 68
		5180 108
		5195 90
		5196 140
		5208 270
		5213 150
		5219 30
		5263 4
		5276 275
		5372 10
		5374 20
		5376 40
		5401 10
		5403 120
		5416 28
		5424 40
		5570 66
		5597 100
		5598 200
		5614 162
		5615 231
		5676 38
		5679 10
		5740 42
		5857 83
		6041 183
		6058 160
		6060 226
		6061 30
		6131 55
		6141 44
		6199 1
		6207 33
		6208 86
		6209 155
		6219 96
		6222 90
		6223 222
		6252 150
		6254 30
		6255 15
		6257 180
		6278 120
		6295 11
		6297 11
		6304 75
		6305 66
		6306 300
		6343 10
		6344 75
		6350 15
		6351 22
		6352 30
		6353 703
		6411 70
		6435 50
		6465 200
		6469 300
		6531 240
		6535 75
		6546 28
		6547 45
		6548 66
		6552 20
		6554 50
		6555 42
		6572 13
		6574 20
		6636 100
		6647 25
		6660 42
		6725 125
		6727 10
		6751 4
		6760 7
		6761 13
		6762 20
		6772 25
		6780 148
		6789 287
		6814 108
		6894 200
		6910 30
		6917 60
		6945 20
		6949 10
		6958 10
		6996 100
		7082 100
		7101 145
		7122 20
		7124 1000
		7125 340
		7268 24
		7269 36
		7270 56
		7277 1
		7288 13
		7290 1
		7295 35
		7322 78
		7365 10
		7367 270
		7372 18
		7373 45
		7379 28
		7395 50
		7400 31
		7402 46
		7482 50
		7588 275
		7641 217
		7648 324
		7651 41
		7668 5
		7712 2
		7714 4
		7715 6
		7716 8
		7717 10
		7718 12
		7719 14
		7739 162
		7750 75
		7799 13
		7800 24
		7801 35
		7802 51
		7803 75
		7814 33
		7815 44
		7816 60
		7914 300
		7938 50
		7947 12
		7951 50
		7978 30
		8000 55
		8034 32
		8037 48
		8042 18
		8044 33
		8045 62
		8046 123
		8050 45
		8052 89
		8053 174
		8056 92
		8058 213
		8060 178
		8078 25
		8079 30
		8092 41
		8102 75
		8103 116
		8104 172
		8105 224
		8106 288
		8142 200
		8147 75
		8150 100
		8187 22
		8198 23
		8204 37
		8205 55
		8208 50
		8242 20
		8246 161
		8256 360
		8257 22
		8265 65
		8275 338
		8288 155
		8289 295
		8292 147
		8293 75
		8295 200
		8313 40
		8331 60
		8332 60
		8333 53
		8338 50
		8349 52
		8363 338
		8364 4
		8382 2
		8398 233
		8400 183
		8401 260
		8402 327
		8406 132
		8407 182
		8408 237
		8412 185
		8413 266
		8418 115
		8419 83
		8422 208
		8423 295
		8427 65
		8433 50
		8435 5
		8437 60
		8438 101
		8439 145
		8444 85
		8445 110
		8446 146
		8492 153
		8502 109
		8503 196
		8510 2000
		8511 1000
		8555 200
		8598 86
		8600 646
		8623 30
		8624 44
		8629 32
		8631 162
		8632 222
		8633 282
		8639 23
		8640 32
		8646 2
		8680 22
		8685 34
		8689 50
		8699 10
		8714 25
		8800 200
		8806 6
		8809 750
		8814 150
		8818 216
		8823 27
		8824 46
		8873 5
		8893 75
		8905 199
		8921 20
		8924 47
		8925 80
		8926 124
		8927 191
		8928 253
		8929 327
		8949 152
		8950 221
		8951 307
		9002 60
		9003 60
		9004 60
		9007 90
		9034 326
		9053 75
		9057 20
		9081 75
		9162 60
		9275 167
		9373 2
		9433 192
		9435 750
		9481 150
		9483 43
		9487 21
		9488 39
		9492 24
		9493 36
		9532 75
		9552 146
		9573 10
		9574 30
		9575 1000
		9591 75
		9613 75
		9654 75
		9658 20
		9672 56
		9734 50
		9739 50
		9752 54
		9754 60
		9770 8
		9771 70
		9773 205
		9776 8
		9779 98
		9796 230
		9824 120
		9826 150
		9833 406
		9834 491
		9835 589
		9852 200
		9853 270
		9874 700
		9875 395
		9876 485
		9894 72
		9896 102
		9904 154
		9908 83
		9912 250
		9915 50
		10017 50
		10018 50
		10073 500
		10093 20
		10136 200
		10148 406
		10149 501
		10150 602
		10151 710
		10159 213
		10160 277
		10161 350
		10179 304
		10180 368
		10181 446
		10185 90
		10186 117
		10187 149
		10197 363
		10199 470
		10201 194
		10202 253
		10205 177
		10206 220
		10207 254
		10215 391
		10216 502
		10230 75
		10253 2
		10266 260
		10267 153
		10268 800
		10273 151
		10274 192
		10277 42
		10312 323
		10313 416
		10314 534
		10318 533
		10319 533
		10336 69
		10337 103
		10341 50
		10346 10
		10373 300
		10391 241
		10392 299
		10412 232
		10413 370
		10414 531
		10419 224
		10420 293
		10435 39
		10436 47
		10444 1
		10447 304
		10448 462
		10451 1000
		10452 20
		10455 10
		10458 76
		10472 343
		10473 500
		10578 371
		10579 37
		10580 54
		10581 75
		10591 301
		10592 445
		10605 522
		10733 4
		10734 35
		10771 350
		10797 72
		10860 1000
		10892 510
		10893 672
		10894 852
		10933 305
		10934 393
		10945 356
		10946 437
		10947 517
		11015 10
		11016 1
		11021 90
		11082 5
		11084 269
		11085 147
		11113 170
		11131 375
		11264 50
		11273 45
		11274 62
		11275 85
		11285 55
		11286 75
		11289 348
		11290 438
		11299 68
		11300 96
		11306 299
		11307 419
		11335 76
		11336 105
		11337 130
		11351 50
		11353 80
		11354 108
		11366 220
		11391 400
		11428 70
		11430 20
		11433 89
		11442 36
		11469 88
		11470 68
		11471 48
		11481 600
		11504 250
		11538 56
		11539 36
		11572 98
		11573 126
		11574 147
		11580 82
		11581 103
		11600 48
		11601 71
		11638 30
		11639 144
		11658 150
		11659 298
		11660 381
		11661 481
		11665 389
		11667 557
		11668 743
		11671 486
		11672 666
		11675 455
		11677 155
		11678 226
		11681 139
		11682 208
		11683 2085
		11684 3120
		11699 55
		11700 71
		11762 71
		11763 88
		11778 73
		11779 87
		11780 99
		11790 15
		11815 450
		11821 1000
		11824 113
		11825 113
		11828 157
		11829 98
		11831 30
		11836 333
		11839 75
		11898 20
		11918 30
		11921 56
		11922 50
		11962 146
		11968 1
		11969 106
		11970 106
		11972 10
		11975 58
		11977 45
		11978 2
		11983 12
		11985 75
		11988 75
		11989 75
		11990 3
		12020 10
		12054 65
		12058 100
		12167 112
		12170 18
		12188 8
		12251 180
		12278 50
		12280 180
		12354 250
		12419 250
		12421 175
		12466 150
		12468 147
		12470 159
		12471 112
		12505 280
		12522 387
		12523 498
		12524 617
		12525 755
		12526 903
		12527 1071
		12533 28
		12538 100
		12540 20
		12543 300
		12545 50
		12548 92
		12549 100
		12553 113
		12555 15
		12557 75
		12559 1
		12562 400
		12611 112
		12625 9
		12626 18
		12654 0
		12667 500
		12674 105
		12675 168
		12693 40
		12721 4
		12723 0
		12734 112
		12737 112
		12739 150
		12742 292
		12744 1
		12747 33
		12748 30
		12766 450
		12871 0
		12884 28
		12891 28
		13018 221
		13019 303
		13020 399
		13021 503
		13022 549
		13140 75
		13184 65
		13237 450
		13238 450
		13239 7500
		13241 1100
		13259 350
		13261 350
		13279 600
		13281 115
		13298 240
		13318 100
		13319 400
		13322 56
		13339 120
		13340 120
		13341 180
		13342 180
		13374 120
		13375 113
		13376 1
		13381 68
		13382 68
		13398 45
		13438 49
		13439 25
		13440 30
		13441 60
		13442 35
		13443 45
		13445 65
		13466 700
		13480 75
		13482 15
		13486 65
		13491 4
		13493 600
		13518 25
		13519 30
		13526 70
		13527 90
		13530 45
		13532 7
		13549 40
		13550 80
		13551 140
		13552 210
		13553 290
		13554 385
		13555 490
		13579 20
		13582 24
		13608 75
		13728 115
		13729 100
		13738 130
		13745 144
		13748 108
		13797 105
		13808 175
		13812 130
		13821 350
		13860 75
		13878 54
		13880 600
		13884 360
		13895 1500
		13897 40
		13899 200
		13900 150
		13901 54
		13907 100
		14030 112
		14032 216
		14034 112
		14087 60
		14103 130
		14105 85
		14106 40
		14109 155
		14110 120
		14118 150
		14119 35
		14122 45
		14126 130
		14145 240
		14147 510
		14200 30
		14267 25
		14268 50
		14269 45
		14270 75
		14271 115
		14281 21
		14282 33
		14283 59
		14284 83
		14285 115
		14286 145
		14287 183
		14294 65
		14295 80
		14296 150
		14298 215
		14299 340
		14300 510
		14301 690
		14314 187
		14315 262
		14331 170
		14517 27
		14518 50
		14792 120
		14795 60
		14797 80
		14868 170
		14871 75
		14874 75
		14875 340
		14887 112
		14903 15
		14907 30
		14914 136
		15037 48
		15039 100
		15040 65
		15043 112
		15063 60
		15089 92
		15091 87
		15095 130
		15096 152
		15117 100
		15124 81
		15207 368
		15208 443
		15228 225
		15230 162
		15232 225
		15234 168
		15236 226
		15237 121
		15238 150
		15239 450
		15241 108
		15242 188
		15243 112
		15244 150
		15245 150
		15249 40
		15253 173
		15254 216
		15261 624
		15262 169
		15263 231
		15264 288
		15265 358
		15266 444
		15267 536
		15285 150
		15305 300
		15306 330
		15407 75
		15430 177
		15431 229
		15432 134
		15433 159
		15451 270
		15453 288
		15472 300
		15475 648
		15497 84
		15498 75
		15499 138
		15500 170
		15501 172
		15505 292
		15530 196
		15531 120
		15532 45
		15536 75
		15537 188
		15538 200
		15547 63
		15548 37
		15549 45
		15570 438
		15574 240
		15575 150
		15583 150
		15587 150
		15588 75
		15592 225
		15598 70
		15605 283
		15607 63
		15608 300
		15609 150
		15610 3
		15611 38
		15612 57
		15614 4
		15615 45
		15616 200
		15618 4
		15619 68
		15620 84
		15643 200
		15653 112
		15654 288
		15655 40
		15659 150
		15661 146
		15662 150
		15664 18
		15665 23
		15668 300
		15691 1
		15692 2
		15695 120
		15712 150
		15732 219
		15736 56
		15743 1250
		15744 131
		15783 6
		15788 100
		15791 112
		15795 84
		15797 38
		15798 112
		15801 150
		15847 800
		15851 65
		15860 60
		15968 33
		15969 198
		15976 50
		15979 108
		16000 105
		16001 120
		16005 9
		16006 200
		16033 500
		16034 575
		16046 174
		16067 120
		16071 3750
		16075 1750
		16079 318
		16094 300
		16095 170
		16099 150
		16100 168
		16101 113
		16102 294
		16128 810
		16141 900
		16143 9000
		16144 360
		16168 600
		16186 646
		16243 125
		16248 60
		16249 84
		16250 113
		16340 75
		16346 27
		16350 1300
		16352 122
		16353 159
		16359 210
		16368 1
		16375 100
		16390 20
		16393 70
		16396 20
		16400 30
		16401 150
		16402 75
		16403 45
		16405 75
		16406 80
		16407 30
		16408 25
		16409 35
		16410 160
		16411 160
		16412 162
		16413 79
		16414 45
		16415 236
		16419 441
		16427 360
		16430 350
		16432 1200
		16433 20
		16452 10000
		16454 60
		16455 200
		16456 150
		16495 100
		16496 252
		16509 135
		16528 50
		16534 2000
		16536 30
		16549 432
		16552 60
		16553 500
		16554 50
		16559 150
		16564 50
		16565 250
		16568 120
		16570 270
		16573 108
		16576 50
		16583 113
		16596 125
		16603 10
		16608 30
		16614 3
		16627 300
		16628 300
		16629 600
		16635 159
		16666 800
		16782 50
		16783 100
		16784 140
		16785 250
		16786 15
		16788 226
		16790 70
		16793 250
		16799 112
		16803 60
		16804 148
		16805 3000
		16806 300
		16827 5
		16828 10
		16829 14
		16830 19
		16831 25
		16832 31
		16837 0
		16844 50
		16866 134
		16868 150
		16898 100
		16914 70
		16921 125
		16997 150
		17086 1500
		17087 1500
		17088 1500
		17089 1500
		17090 1500
		17091 1500
		17092 1500
		17093 1500
		17094 1500
		17095 1500
		17097 1500
		17140 143
		17141 286
		17142 429
		17144 80
		17145 174
		17146 432
		17147 90
		17148 250
		17149 180
		17153 560
		17157 76
		17158 120
		17165 240
		17170 220
		17171 33
		17173 16
		17183 120
		17194 187
		17195 135
		17196 200
		17197 300
		17203 113
		17228 150
		17234 226
		17238 96
		17253 8
		17255 17
		17256 26
		17257 34
		17258 44
		17259 54
		17260 73
		17261 90
		17273 232
		17274 928
		17276 100
		17277 87
		17278 500
		17281 75
		17283 125
		17287 400
		17289 339
		17290 300
		17291 500
		17292 120
		17293 1600
		17294 20
		17311 126
		17312 186
		17313 261
		17314 330
		17330 150
		17353 21
		17366 212
		17393 338
		17399 226
		17401 100
		17402 134
		17407 250
		17434 338
		17435 338
		17439 170
		17445 1200
		17447 300
		17466 150
		17470 1000
		17471 10
		17483 270
		17484 60
		17492 240
		17496 20
		17501 50
		17503 196
		17504 120
		17506 120
		17509 235
		17510 30
		17511 80
		17616 1500
		17620 48
		17631 150
		17652 10
		17669 200
		17686 5000
		17689 1500
		17692 50
		17698 30
		17716 200
		17731 1500
		17739 500
		17742 350
		17745 100
		17771 340
		17809 30
		17831 35
		17877 93
		17883 438
		17919 65
		17920 95
		17921 134
		17922 173
		17923 222
		17924 792
		17925 375
		17926 470
		17933 50
		17934 75
		17935 100
		17962 273
		18075 50
		18077 15
		18078 30
		18081 108
		18082 132
		18083 96
		18084 30
		18085 65
		18086 150
		18088 90
		18089 60
		18090 102
		18091 85
		18092 35
		18099 150
		18104 108
		18105 252
		18106 840
		18107 108
		18108 336
		18111 260
		18112 700
		18138 125
		18139 50
		18147 1
		18150 9
		18152 50
		18164 150
		18165 286
		18187 60
		18197 35
		18199 116
		18200 130
		18202 110
		18203 105
		18204 115
		18205 70
		18206 170
		18208 65
		18211 200
		18214 150
		18217 80
		18235 20
		18236 30
		18265 15
		18266 85
		18270 538
		18276 90
		18277 1
		18279 30
		18289 275
		18351 1500
		18352 1500
		18353 1500
		18354 1500
		18355 1500
		18356 1500
		18357 1500
		18358 1500
		18359 1500
		18360 1500
		18361 1500
		18374 25
		18376 480
		18389 5000
		18390 10000
		18392 2000
		18394 1
		18398 45
		18399 196
		18432 3000
		18435 3500
		18500 750
		18543 73
		18557 16
		18561 42
		18564 1500
		18565 1500
		18566 1500
		18567 1500
		18568 1500
		18569 1500
		18570 1500
		18571 1500
		18572 1500
		18573 1500
		18574 1500
		18575 1500
		18576 1500
		18578 1500
		18579 1500
		18580 1500
		18581 1500
		18582 1500
		18583 1500
		18584 1500
		18585 1500
		18586 1500
		18587 1500
		18588 1500
		18589 1500
		18590 1500
		18591 1500
		18592 1500
		18593 1500
		18594 1500
		18595 1500
		18596 1500
		18597 1500
		18598 1500
		18599 1500
		18600 1500
		18601 1500
		18602 1500
		18603 1500
		18604 1500
		18605 1500
		18606 1500
		18607 1500
		18609 1500
		18611 1500
		18612 1500
		18613 1500
		18614 1500
		18615 1500
		18616 1500
		18617 1500
		18618 1500
		18619 1500
		18620 1500
		18621 1500
		18622 1500
		18623 1500
		18624 1500
		18625 1500
		18626 1500
		18627 1500
		18628 1500
		18633 120
		18649 99
		18652 160
		18656 210
		18663 226
		18671 510
		18763 750
		18796 200
		18798 50
		18807 426
		18809 1071
		18812 70
		18817 35
		18818 100
		18833 90
		18867 123
		18868 198
		18869 277
		18870 371
		18871 476
		18879 22
		18880 33
		18881 45
		18930 356
		18931 431
		18932 502
		18944 900
		18949 400
		18958 60
		18977 50
		18980 20
		19099 250
		19128 70
		19129 1000
		19130 36
		19133 180
		19136 165
		19196 1000
		19237 800
		19249 15
		19251 24
		19252 35
		19253 48
		19254 64
		19260 205
		19272 1250
		19276 34
		19277 50
		19278 68
		19279 89
		19280 113
		19296 135
		19299 246
		19302 354
		19303 486
		19304 642
		19305 798
		19306 40
		19307 300
		19391 225
		19393 4000
		19428 3200
		19448 120
		19450 850
		19452 100
		19460 452
		19463 75
		19469 100
		19474 200
		19482 160
		19497 2000
		19513 75
		19627 250
		19628 750
		19630 1500
		19637 3000
		19641 1500
		19698 1
		19701 43
		19702 2000
		19712 1000
		19717 1000
		19728 2500
		19729 2500
		19767 42
		19769 400
		19771 1500
		19776 720
		19780 350
		19781 1000
		19784 450
		19785 2500
		19798 1500
		19806 70
		19810 70
		19811 4000
		19816 98
		19820 3000
		19874 215
		19901 50000
		19970 270
		19971 200
		19972 140
		19973 90
		19974 50
		19975 20
		20004 30
		20019 1500
		20021 250
		20116 15
		20153 25
		20187 12
		20203 530
		20228 2300
		20229 750
		20253 25
		20276 500
		20280 20
		20281 32
		20282 47
		20283 64
		20284 84
		20285 107
		20286 133
		20294 3600
		20295 98
		20296 128
		20297 73
		20298 98
		20299 130
		20420 1500
		20463 420
		20467 24
		20473 212
		20476 3200
		20479 8000
		20483 3500
		20527 1500
		20532 1500
		20535 76
		20536 114
		20539 200
		20542 1000
		20543 152
		20559 71
		20560 93
		20564 7200
		20565 6000
		20566 1000
		20586 100
		20602 159
		20603 800
		20614 45
		20615 65
		20623 1200
		20627 114
		20629 120
		20630 152
		20647 1
		20654 250
		20657 375
		20667 240
		20678 1600
		20679 1400
		20680 1000
		20685 1500
		20687 800
		20690 2400
		20692 1600
		20694 800
		20695 1500
		20696 1500
		20698 1200
		20699 1750
		20712 900
		20714 188
		20716 75
		20717 150
		20720 162
		20726 200
		20733 2400
		20741 300
		20743 96
		20754 6
		20787 219
		20791 86
		20792 65
		20793 86
		20794 112
		20795 138
		20797 86
		20800 168
		20801 26
		20802 86
		20805 92
		20806 69
		20807 92
		20808 92
		20811 92
		20813 120
		20815 98
		20816 98
		20819 73
		20820 65
		20821 98
		20822 79
		20823 105
		20824 105
		20825 105
		20826 207
		20827 137
		20828 105
		20829 76
		20830 105
		20831 140
		20832 168
		20869 75
		20883 70
		20893 200
		20907 105
		20908 133
		20909 70
		20910 110
		20922 24
		20923 35
		20924 48
		20929 290
		20930 380
		20963 38
		20964 53
		20965 67
		20966 82
		21008 31
		21027 4
		21030 106
		21047 75
		21058 4000
		21059 112
		21066 4000
		21067 60
		21068 160
		21069 105
		21070 150
		21071 43
		21072 98
		21073 58
		21077 1500
		21096 12
		21097 7
		21098 850
		21099 1000
		21131 25000
		21132 25000
		21133 25000
		21135 25000
		21136 25000
		21137 25000
		21138 25000
		21139 25000
		21140 240
		21141 150
		21151 75
		21155 2000
		21158 1000
		21159 108
		21162 378
		21170 140
		21179 200
		21331 100
		21333 750
		21341 750
		21367 400
		21369 750
		21401 184
		21402 150
		21547 500
		21549 98
		21559 800
		21667 750
		21668 1000
		21669 1600
		21687 125
		21748 75
		21749 150
		21787 36
		21793 345
		21807 100
		21832 450
		21868 150
		21889 300
		21910 175
		21912 0
		21949 230
		21952 90
		21961 160
		21971 125
		21978 100
		21992 300
		22048 10
		22088 900
		22121 105
		22127 83
		22191 500
		22192 500
		22193 500
		22194 500
		22195 500
		22196 500
		22197 500
		22198 500
		22199 500
		22200 500
		22201 500
		22202 500
		22206 224
		22267 1500
		22268 25000
		22271 173
		22273 224
		22275 588
		22284 1500
		22290 750
		22312 1250
		22335 30
		22336 450
		22355 200
		22357 196
		22411 42
		22412 540
		22414 168
		22415 133
		22419 100
		22422 500
		22423 3400
		22424 262
		22425 300
		22433 1000
		22439 750
		22442 150
		22460 253
		22478 1000
		22479 750
		22482 0
		22498 1500
		22519 30
		22539 4500
		22558 1500
		22559 750
		22560 1250
		22568 22
		22570 3
		22575 226
		22582 180
		22595 200
		22600 30
		22639 150
		22642 900
		22643 168
		22644 30
		22645 120
		22662 1850
		22665 300
		22677 300
		22682 20000
		22689 2000
		22694 1500
		22699 200
		22703 200
		22709 1000
		22713 20
		22741 400
		22743 150
		22746 150
		22800 1000
		22802 400
		22822 18
		22823 30
		22827 32
		22828 50
		22829 70
		22851 1
		22853 1
		22861 1
		22862 1
		22878 75
		22885 344
		22887 210
		22893 100
		22907 252
		22908 300
		22919 720
		22920 1000
		22924 600
		22937 400
		22938 58
		22940 200
		22945 600
		22946 75
		22948 2500
		22965 1
		22966 1
		22972 750
		22975 750
		22976 750
		22977 750
		22978 750
		22979 750
		22980 750
		22981 750
		22982 750
		22983 750
		22984 750
		22985 750
		22993 20000
		22994 83
		23000 250
		23001 250
		23011 1500
		23023 3000
		23038 144
		23039 121
		23055 100
		23063 400
		23073 35
		23102 112
		23104 283
		23105 75
		23106 200
		23113 131
		23114 172
		23115 138
		23155 10000
		23169 30000
		23187 2000
		23189 2000
		23202 204
		23206 200
		23226 1500
		23267 48
		23268 432
		23269 1750
		23275 600
		23278 85
		23298 2775
		23299 900
		23308 4200
		23309 4200
		23313 5000
		23314 5000
		23315 15000
		23316 15000
		23331 3000
		23337 63
		23339 750
		23341 150
		23364 1250
		23379 575
		23380 156
		23391 83
		23392 166
		23402 6000
		23411 710
		23412 457
		23413 259
		23417 600
		23461 9000
		23462 600
		23478 2500
		23504 10000
		23512 300
		23580 300
		23590 125
		23592 45
		23618 1100
		23675 50
		23687 250
		23722 200
		23773 3000
		23774 3000
		23858 1000
		23860 3000
		23861 500
		23862 3000
		23865 1500
		23881 40
		23892 40
		23893 40
		23894 40
		23918 2000
		23922 320
		23923 380
		23924 440
		23925 500
		23931 1500
		23952 2700
		23953 7500
		23970 1000
		23972 1000
		23979 300
		24011 1200
		24020 1250
		24024 5000
		24049 2500
		24050 600
		24063 500
		24097 360
		24099 2250
		24111 4500
		24112 1000
		24118 77
		24119 105
		24120 133
		24131 300
		24134 420
		24135 600
		24150 300
		24152 938
		24170 2550
		24189 1000
		24192 3500
		24212 4500
		24234 100
		24238 102
		24239 530
		24241 564
		24251 84
		24254 78
		24257 210
		24265 150
		24274 420
		24275 320
		24300 500
		24306 2000
		24321 2000
		24323 4000
		24328 1000
		24330 600
		24331 56
		24332 112
		24334 112
		24336 1500
		24339 4500
		24374 1000
		24388 250
		24393 276
		24423 8
		24435 1000
		24437 300
		24458 650
		24530 500
		24577 14
		24578 22
		24579 36
		24583 12
		24585 51
		24586 24
		24587 32
		24611 750
		24612 1325
		24615 400
		24616 226
		24618 300
		24640 8
		24648 833
		24649 1250
		24668 750
		24669 500
		24671 1000
		24672 2000
		24680 1000
		24682 1250
		24683 1500
		24685 1250
		24687 1500
		24688 2000
		24698 20
		24767 1250
		24779 0
		24803 1500
		24811 1750
		24818 4000
		24819 500
		24820 1000
		24821 1000
		24822 1000
		24823 1000
		24826 2000
		24835 1000
		24836 1000
		24837 1000
		24838 1000
		24839 3250
		24840 350
		24844 12
		24857 1200
		24871 2750
		24929 1000
		24933 20
		24942 56
		24957 650
		24974 138
		24975 174
		24976 264
		24977 324
		24993 96
		25003 35
		25008 22
		25009 38
		25010 55
		25011 84
		25012 106
		25019 12
		25021 300
		25025 344
		25028 1250
		25029 20
		25030 10
		25031 15
		25032 5
		25033 1500
		25034 1250
		25049 1500
		25052 224
		25053 1800
		25099 40

		25288 90
	}

	# restoring spells (mainly healing for now) ([lsearch "10" $se] >= 0 || [lsearch "6 27 35" $se] >= 0 && [lsearch "8" $sa] >= 0)
	# added Power Word: Shield
	# todo: find some workaround for mana (not sure how)
	# spellid -> threat
	variable SpellRestore
	array set SpellRestore {
		18 15
		22 50
		24 43
		49 15
		118 20000
		139 54
		331 39
		332 71
		439 80
		440 160
		441 320
		547 142
		596 311
		633 2000
		635 43
		639 83
		647 173
		687 3
		696 5
		706 7
		740 94
		746 66
		774 40
		812 15
		820 1
		833 30
		913 292
		939 408
		959 579
		996 458
		1026 333
		1042 522
		1058 70
		1064 344
		1086 9
		1136 16
		1159 114
		1181 1
		1182 2
		1183 3
		1430 145
		1848 0
		2024 520
		2048 1489
		2050 51
		2052 78
		2053 146
		2054 318
		2055 535
		2060 1277
		2061 215
		2062 222
		2063 1303
		2064 1845
		2090 225
		2091 305
		2370 120
		2400 40
		2597 30
		2599 240
		2600 425
		2638 60
		2640 180
		2690 10
		2800 4000
		3267 161
		3268 301
		3359 110
		3368 50
		3472 739
		3591 400
		3627 380
		4042 800
		4143 39
		4209 67
		4221 107
		4312 10
		4506 1
		4947 0
		4961 300
		4970 500
		5016 75
		5025 1
		5174 120
		5185 44
		5186 100
		5187 219
		5188 404
		5189 633
		5281 24
		5400 10
		5402 1000
		5576 35
		5578 50
		5607 15
		5672 6
		5707 10
		5718 5
		5719 10
		5720 500
		5723 800
		6063 805
		6064 1010
		6074 120
		6075 210
		6076 294
		6077 378
		6078 480
		6260 1
		6261 3
		6262 100
		6263 250
		6275 35
		6367 19
		6368 32
		6369 47
		6370 60
		6371 8
		6372 10
		6373 52
		6374 74
		6497 15
		6778 818
		6925 10000
		7099 10
		7106 100
		7144 150
		7154 200
		7200 4
		7291 10
		7331 10
		7638 150
		7673 0
		7926 400
		7927 640
		7948 500
		8004 174
		8005 797
		8008 264
		8010 359
		8065 450
		8070 180
		8141 350
		8348 78
		8362 33
		8595 8
		8812 1080
		8903 1028
		8910 485
		8918 138
		8936 203
		8938 376
		8939 553
		8940 731
		8941 919
		9163 300
		9472 286
		9473 360
		9474 439
		9616 300
		9750 1167
		9758 1313
		9777 80
		9839 488
		9840 760
		9841 945
		9856 1469
		9857 1841
		9858 2277
		9862 205
		9863 294
		9888 1656
		9889 2060
		9956 300
		10260 3000
		10310 6000
		10328 999
		10329 1317
		10345 500
		10395 1092
		10396 1464
		10460 12
		10461 14
		10466 486
		10467 668
		10468 880
		10577 400
		10622 435
		10623 590
		10838 800
		10839 1104
		10915 567
		10916 704
		10917 885
		10927 612
		10928 780
		10929 972
		10960 676
		10961 965
		10963 1624
		10964 2033
		10965 2535
		11014 540
		11387 751
		11431 346
		11640 150
		11642 425
		11695 1530
		11732 1200
		11733 11
		11734 13
		11735 15
		11895 2400
		11900 150
		11986 258
		12039 637
		12139 750
		12160 140
		12491 386
		12492 515
		12824 30000
		12825 40000
		12826 50000
		12939 1
		13857 202
		13908 152
		13951 1000
		13952 252
		14053 150
		14816 0
		14900 175
		15068 1000
		15229 670
		15237 196
		15278 12
		15290 0
		15347 24
		15430 284
		15431 366
		15493 504
		15503 425
		15504 637
		15585 404
		15586 950
		15700 800
		15701 425
		15731 20
		15799 350
		15822 1200
		15870 116
		15981 352
		15982 750
		16319 5000
		16367 525
		16561 424
		16569 2000
		16588 425
		16599 200
		16637 10000
		16916 360
		17012 1000
		17137 215
		17138 648
		17448 500
		17484 60
		17534 1400
		17613 638
		17625 10
		17712 500
		17843 430
		18222 720
		18386 600
		18608 1360
		18610 2000
		18653 150
		18764 3
		18805 200
		18832 600
		18956 250
		18957 400
		18984 50
		19199 1400
		19236 294
		19238 495
		19240 648
		19241 914
		19242 1203
		19243 1443
		19362 1000
		19658 234
		19732 319
		19733 438
		19735 579
		19750 67
		19775 30000
		19939 103
		19940 154
		19941 209
		19942 283
		19943 363
		19952 10000
		19968 1
		19980 1
		19981 1
		19982 1
		19993 1
		20007 100
		20167 39
		20267 25
		20333 53
		20334 76
		20340 94
		20341 34
		20342 49
		20343 61
		20512 1277
		20631 1000
		20655 20000
		20664 704
		20665 2120
		20701 8000
		20713 682
		20790 300
		20810 50
		20885 5
		20892 30
		20894 40
		20969 5
		21054 70000
		21064 25000
		21109 8
		21168 3
		21345 1
		21346 2
		21347 3
		21348 4
		21349 6
		21350 9
		21393 1120
		21394 640
		21399 0
		21587 1
		21588 1
		21589 1
		21590 1
		21592 2
		21593 2
		21594 2
		21595 3
		21596 3
		21597 3
		21598 4
		21599 4
		21600 4
		21601 5
		21602 5
		21603 5
		21604 6
		21605 6
		21606 6
		21607 7
		21608 7
		21609 7
		21610 7
		21611 8
		21612 8
		21613 8
		21614 9
		21615 9
		21616 9
		21617 10
		21791 64
		21955 600
		22009 315
		22167 950
		22168 33
		22373 848
		22458 20000
		22695 848
		22729 1600
		22806 0
		22845 1
		22883 1900
		23064 500
		23108 250
		23117 150
		23168 150000
		23210 14
		23381 484
		23394 25000
		23455 196
		23458 284
		23459 366
		23468 110
		23469 120
		23470 275
		23471 300
		23472 550
		23473 600
		23474 880
		23475 960
		23476 1320
		23477 1440
		23544 200
		23567 2000
		23568 1104
		23569 640
		23580 300
		23583 500
		23682 150
		23696 2000
		23781 35
		23783 0
		23858 2000
		23880 10
		23889 13
		23890 17
		23891 20
		23895 10000
		23954 100000
		24022 2500
		24206 0
		24208 40000
		24209 100000
		24311 10000
		24360 2100
		24379 5010
		24412 640
		24413 1104
		24414 2000
		24427 108
		24804 15000
		25062 425
		25142 0
		25155 65


		17 44
		592 88
		600 158
		3747 234
		6065 301
		6066 381
		10898 484
		10899 605
		10900 763
		10901 942
	}

	# todo
	# Tranquil Air Totem


	# change "from"'s threat level towards "to"
	proc ChangeThreat {to from threat} {
		variable Data${to}
		variable Attacker${from}
		variable ModThreat

		# check for temporary mod threat
		if {[info exists ModThreat($from)]} {
			if {[clock seconds] > [lindex $ModThreat($from) 1]} {
				unset ModThreat($from)
			} else {
				incr threat [expr {abs($threat) * [lindex $ModThreat($from) 0] / 100}]
			}
		}

		if {[info exists Data${to}($from)]} {
			set Attacker${from}($to) [incr Data${to}($from) $threat]
		} else {
			set Attacker${from}($to) [set Data${to}($from) $threat]
		}

		if {[set Data${to}($from)] < 0} {
			set Data${to}($from) 0
		}

		return [set Data${to}($from)]
	}

	# get "from"'s threat level towards "to"
	proc GetThreat {to from} {
		variable Data${to}
		variable ModTotalThreat

		if {![info exists Data${to}($from)]} {
			return 0
		}

		set threat [set Data${to}($from)]

		# check for temporary mod total threat
		if {[info exists ModTotalThreat($from)]} {
			if {[clock seconds] > [lindex $ModTotalThreat($from) 1]} {
				unset ModTotalThreat($from)
			} else {
				incr threat [lindex $ModTotalThreat($from) 0]
			}
		}

		if {$threat < 0} {
			set threat 0
		}

		return $threat
	}

	# get a mob's current melee target
	proc GetTarget {to} {
		variable Target

		if {[info exists Target($to)]} {
			set from $Target($to)

			if {[::GetObjectType $from]} {
				return $from
			}

			variable Data${to}
			variable Attacker${from}

			array unset Data${to} $from
			array unset Attacker${from} $to
			unset Target($to)
		}

		return 0
	}

	# get a list of a mob's enemies
	proc GetEnemies {to} {
		variable Data${to}
		set enemies {}

		foreach {enemy} [array names Data${to}] {
			if {![::GetObjectType $enemy]} {
				variable Attacker${enemy}

				array unset Attacker${enemy} $to
				unset Data${to}($enemy)
				continue
			}

			lappend enemies $enemy
		}

		return $enemies
	}

	# find a mob's most threatful enemy
	proc GetHighestThreat {to} {
		variable Data${to}
		variable ModTotalThreat
		set max [list -1 0]

		foreach {enemy} [array names Data${to}] {
			if {![::GetObjectType $enemy]} {
				variable Attacker${enemy}

				array unset Attacker${enemy} $to
				unset Data${to}($enemy)
				continue
			}

			set threat [GetThreat $to $enemy]

			if {$threat > [lindex $max 0]} {
				set max [list $threat $enemy]
			}
		}

		return [lindex $max 1]
	}

	# check threat level and switch melee target if appropriate
	# todo: maybe differentiate threshold for melee and out of melee range
	proc CheckThreat {to from} {
		variable THRESHOLD

		if {[set target [GetTarget $to]] != $from &&
			[GetThreat $to $from] >= [GetThreat $to $target] * $THRESHOLD / 100 &&
			$from && [::Custom::GetSide $to] != [::Custom::GetSide $from]
		} {
			return [::CastSpell $to $from 22690]
		}

		return 0
	}

	# change threat level towards the target
	proc OnThreat {to from spellid} {
		if {[::GetObjectType $to] != 3} {
			return
		}

		variable SpellThreat

		ChangeThreat $to $from $SpellThreat($spellid)
		CheckThreat $to [GetHighestThreat $to]
	}

	# change threat level towards all attackers (no spell using this for now)
	proc OnThreatAttackers {to from spellid} {
		variable SpellThreatAttackers
		variable Attacker${from}

		foreach attacker [array names Attacker${from}] {
			if {[::GetObjectType $attacker] != 3} {
				variable Data${attacker}

				array unset Data${attacker} $from
				unset Attacker${from}($attacker)
				continue
			}

			ChangeThreat $attacker $from $ThreatAttackers($spellid)
			CheckThreat $attacker [GetHighestThreat $attacker]
		}
	}

	# change all threat levels towards the target
	proc OnThreatAll {to from spellid} {
		if {[::GetObjectType $to] != 3} {
			return
		}

		variable SpellThreatAll
		variable Data${to}

		foreach enemy [array names Data${to}] {
			if {![::GetObjectType $enemy]} {
				variable Attacker${enemy}

				array unset Attacker${enemy} $to
				unset Data${to}($enemy)
				continue
			}

			ChangeThreat $to $enemy $SpellThreatAll($spellid)
		}

		CheckThreat $to [GetHighestThreat $to]
	}

	# mod generated threat
	proc OnModThreat {to from spellid} {
		variable SpellModThreat
		variable ModThreat

		set duration [lindex $::AI::SpellData($spellid) 2]
		set ModThreat($from) [list $SpellModThreat($spellid) [expr {[clock seconds] + ($duration < 0 ? 10 : $duration)}]]
	}

	# mod total threat
	proc OnModTotalThreat {to from spellid} {
		variable SpellModTotalThreat
		variable ModTotalThreat
		variable Attacker${from}

		set duration [lindex $::AI::SpellData($spellid) 2]
		set ModTotalThreat($from) [list $SpellModTotalThreat($spellid) [expr {[clock seconds] + ($duration < 0 ? 10 : $duration)}]]

		foreach attacker [array names Attacker${from}] {
			if {[::GetObjectType $attacker] != 3} {
				variable Data${attacker}

				array unset Data${attacker} $from
				unset Attacker${from}($attacker)
				continue
			}

			CheckThreat $attacker [GetHighestThreat $attacker]
		}
	}

	# mod total threat on the target (used for immunity, confuse, stun, root)
	proc OnModTotalThreatTarget {to from spellid} {
		variable SpellModTotalThreatTarget
		variable ModTotalThreat
		variable Attacker${to}

		set duration [lindex $::AI::SpellData($spellid) 2]
		set ModTotalThreat($to) [list $SpellModTotalThreatTarget($spellid) [expr {[clock seconds] + ($duration < 0 ? 10 : $duration)}]]

		foreach attacker [array names Attacker${to}] {
			if {[::GetObjectType $attacker] != 3} {
				variable Data${attacker}

				array unset Data${attacker} $to
				unset Attacker${to}($attacker)
				continue
			}

			CheckThreat $attacker [GetHighestThreat $attacker]
		}
	}

	# weapon damage
	proc OnWeapon {to from spellid} {
		if {[::GetObjectType $to] != 3} {
			return
		}

		variable SpellWeapon

		ChangeThreat $to $from [expr {$SpellWeapon($spellid) + [::GetLevel $from] * [::Custom::RandInt 1 3]}]
		CheckThreat $to $from
	}

	# spell damage
	proc OnDamage {to from spellid} {
		if {[::GetObjectType $to] != 3} {
			return
		}

		variable SpellDamage

		ChangeThreat $to $from $SpellDamage($spellid)
		CheckThreat $to $from
	}

	# spell restore (healing)
	proc OnRestore {to from spellid} {
		variable SpellRestore
		variable Attacker${to}

		foreach attacker [array names Attacker${to}] {
			if {[::GetObjectType $attacker] != 3} {
				variable Data${attacker}

				array unset Data${attacker} $to
				unset Attacker${to}($attacker)
				continue
			}

			ChangeThreat $attacker $from $SpellRestore($spellid)
			CheckThreat $attacker $from
		}
	}

	# Feign Death (Hunter) (5384)
	# the mob will pause if there are no other available targets
	proc OnFeignDeath {to from spellid} {
		variable FeignDeathData
		variable Attacker${from}
		set player_level [::GetLevel $from]

		::Say $from 0 "[::Custom::DyingScream]"

		foreach attacker [array names ::Threat::Attacker${from}] {
			variable Data${attacker}

			if {[::GetObjectType $attacker] == 3} {
				if {(![info exists FeignDeathData($attacker,$from)] || [clock seconds] > $FeignDeathData($attacker,$from)) &&
					[::GetLevel $attacker] < $player_level + [::Custom::RandInt -5 5]
				} then {
					array unset Data${attacker} $from
					unset Attacker${from}($attacker)


					if {![set highest [GetHighestThreat $attacker]] || ![CheckThreat $attacker $highest]} {
						::CastSpell $attacker $attacker 7950
					}
				} else {
					set FeignDeathData($attacker,$from) [expr {[clock seconds] + 300}]
				}
			} else {
				array unset Data${attacker} $from
				unset Attacker${from}($attacker)
			}
		}
	}

	# fired when having a new melee target (spell 22690), update the mob's target
	proc OnTarget {to from spellid} {
		if {[::GetObjectType $from] != 3} {
			return
		}

		variable Target
		set Target($from) $to

		#variable Attacker${to}
		#set Attacker${to}($from) 1
	}

	# the player moves away from the mob, the mob's threat data for the player
	proc OnUnAgro {command code result op} {
		if {$result} {
			set npc [lindex $command 1]
			set player [lindex $command 2]
			array unset ::Threat::Data${npc} $player
			array unset ::Threat::Attacker${player} $npc
			array unset ::Threat::Target $npc
		}
	}

	# the mob dies, threat data cleanup
	::Custom::HookProc "::WoWEmu::CalcReputation" {
		foreach enemy [array names ::Threat::Data${victim}] {
			array unset ::Threat::Attacker${enemy} $victim
		}

		array unset ::Threat::Data${victim}
		array unset ::Threat::Target $victim
	}

	# the player dies, threat data cleanup
	::Custom::HookProc "::WoWEmu::OnPlayerDeath" {
		foreach attacker [array names ::Threat::Attacker${player}] {
			array unset ::Threat::Data${attacker} $player
		}

		array unset ::Threat::Attacker${player}
		array unset ::Threat::Target $killer
	}

	# the player is hit by the mob, update the mob's target
	::Custom::HookProc "::WoWEmu::DamageReduction" {
		if {![info exists ::Threat::Target($mob)] && [::GetObjectType $mob] == 3} {
			set ::Threat::Attacker${player}($mob) 1
		}
		set ::Threat::Target($mob) $player
	}

	trace add execution "::AI::ModUnAgro" leave "::Threat::OnUnAgro"

	::Custom::AddSpellScript "::Threat::OnThreat" [array names SpellThreat]
	::Custom::AddSpellScript "::Threat::OnThreatAttackers" [array names SpellThreatAttackers]
	::Custom::AddSpellScript "::Threat::OnThreatAll" [array names SpellThreatAll]
	::Custom::AddSpellScript "::Threat::OnModThreat" [array names SpellModThreat]
	::Custom::AddSpellScript "::Threat::OnModTotalThreat" [array names SpellModTotalThreat]
	::Custom::AddSpellScript "::Threat::OnModTotalThreatTarget" [array names SpellModTotalThreatTarget]
	::Custom::AddSpellScript "::Threat::OnWeapon" [array names SpellWeapon]
	::Custom::AddSpellScript "::Threat::OnDamage" [array names SpellDamage]
	::Custom::AddSpellScript "::Threat::OnRestore" [array names SpellRestore]
	::Custom::AddSpellScript "::Threat::OnTarget" 22690 20508
	::Custom::AddSpellScript "::Threat::OnFeignDeath" 5384


	# apply rates
	foreach {spell threat} [array get SpellWeapon] {
		set SpellWeapon($spell) [expr {round($threat * $WEAPON_RATE)}]
	}
	foreach {spell threat} [array get SpellDamage] {
		set SpellDamage($spell) [expr {round($threat * $SPELL_RATE)}]
	}
	foreach {spell threat} [array get SpellRestore] {
		set SpellRestore($spell) [expr {round($threat * $RESTORE_RATE)}]
	}

	::StartTCL::Provide

	if {$DEBUG} {
		puts "\n $NAME: *** DEBUG MODE ENABLED *** \n"
		foreach proc [lsort [info procs]] {
			Custom::TraceCmd [namespace current]::$proc 0
		}
	}
}
